<?php

class UserModel extends \TC\Db\Mysql
{
    const Database_Name = 'zzwtest';
    const Table_Name = 'test';
    protected static $fields_all = '*';

    /**
     * @desc 获取登录时的用户信息
     * @param $account
     * @return array
     * @author zhaozhiwei
     * @date 2021-02-04 9:33
     */
    public static function getUserInfo($account)
    {
        return self::get(static::$fields_all, [
                "OR" => [
                    "account" => $account,
                    "phone" => $account
                ]]) ?? [];
    }

    /**
     * @desc 更新登录信息
     * @param $array
     * @param $user_id
     * @return mixed
     * @author zhaozhiwei
     * @date 2021-02-04 9:35
     */
    public static function updateUserInfo($array, $user_id)
    {
        self::update($array, ['uid' => $user_id]);
        return self::update($array, ['uid' => $user_id]);
    }

    /**
     * @desc 增加积分方法
     * @param $user_id
     * @return mixed
     * @author zhaozhiwei
     * @date 2021-02-04 14:53
     */
    public static function integralChange($array,$user_id)
    {
        return self::update($array, ['uid' => $user_id]);
    }
    //注册信息
    public static function registerUser($array){
        self::insert($array);
        return self::id();
    }
    //通过id获取用户信息
    public static function getUserInfoById($id){
        return self::get(static::$fields_all, ['id'=>$id]) ?? [];
    }
    //根据手机号修改密码
    public static function changePwdByMobile($mobile,$pwd){
        return self::update(['pwd'=>$pwd], ['phone'=>$mobile]) ?? [];
    }
}